package io.github.wslxm.springbootplus2.starter.captcha.config;

import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
import cloud.tianai.captcha.resource.ResourceStore;
import cloud.tianai.captcha.resource.common.model.dto.Resource;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;


@Component
@RequiredArgsConstructor
public class CaptchaResourceConfiguration {

    private final ResourceStore resourceStore;

    @PostConstruct
    public void init() {
        // 添加自定义背景图片
        String[] captchaTypes = {CaptchaTypeConstant.SLIDER, CaptchaTypeConstant.ROTATE, CaptchaTypeConstant.CONCAT, CaptchaTypeConstant.WORD_IMAGE_CLICK};
        for (int i = 0; i < captchaTypes.length; i++) {
            String captchaType = captchaTypes[i];
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/a.jpg", "default"));
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/b.jpg", "default"));
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/c.jpg", "default"));
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/d.jpg", "default"));
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/e.jpg", "default"));
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/f.jpg", "default"));
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/g.jpg", "default"));
            resourceStore.addResource(captchaType, new Resource("classpath", "bgimages/h.jpg", "default"));
        }
    }
}

